﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Piao
{
    static class ImageUtil
    {
        public static void GrayImage(ref Image img)
        {
            Bitmap bmp = new Bitmap(img);

            int height = bmp.Height;
            int width = bmp.Width;
            
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Color c = bmp.GetPixel(x, y);
                    int rgb = Convert.ToInt32((double)(((0.7 * c.R) + (0.2 * c.G)) + (0.1 * c.B)));

                    if (rgb < 150) rgb = 0;
                    if (rgb >= 150) rgb = 255;

                    bmp.SetPixel(x, y, Color.FromArgb(rgb, rgb, rgb));
                }
            }

            img = (Image)bmp;
        }

        public static void SetAlignment(ref Image img)
        {
            Bitmap bmp = new Bitmap(img);
            int height = bmp.Height;
            int width = bmp.Width;


            int startX = 0;
            List<Color> list = new List<Color>();

            for (int x = 0; x < width; x += 1)
            {
                for (int y = 0; y < height; y += 1)
                {
                    Color c = bmp.GetPixel(x, y);

                    

                    if (!list.Contains(c))
                        list.Add(c);
                    
                    if (startX != 0 && c.R < 50)
                    {
                        startX = x;
                    }
                }

                if (startX != 0)
                    break;
            }

            var piece = Math.Truncate(((double)(width - startX) / 8));

            

            img = (Image)bmp;

        }


    }
}
